<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>canvas-demos</title>

    <style>
        canvas {
            margin: 0 auto;
            border: 2px solid #aaa;
            display: block;
        }
    </style>
</head>

<body>
<canvas id="cont" width="500px" height="500px">浏览器不支持</canvas>
<!--只能使用原生的js,如果让canvas左右居中使用display:block-->
<script>
    // 固定start获取画布
    const canvas = document.querySelector('#cont')
    // 获取画布上下文
    const ctx = canvas.getContext('2d')
    // 固定end

    // 后描边[必须]
    ctx.lineWidth = 5
    ctx.strokeStyle = 'red'

    const totalAngle = Math.PI * 2
    const leg = Math.PI / 12
    let startAngle = 0
    let endAngle = leg
    const timerId = setInterval(function () {
        ctx.arc(250, 250, 200, startAngle, endAngle, false)
        ctx.stroke()
        startAngle = endAngle
        endAngle += leg
        if (endAngle > totalAngle) {
            clearInterval(timerId)
        }
    }, 50);
</script>
</body>
</html>
